package com.sg.business.work.condition;

import org.jbpm.task.Status;

import com.mobnut.db.model.IRelationConditionProvider;
import com.mobnut.db.model.PrimaryObject;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.sg.business.model.IProcessControl;
import com.sg.business.model.UserTask;
import com.sg.business.model.Work;

public class WorkOfUserTaskConditionProvider implements
		IRelationConditionProvider {

	@Override
	public DBObject getCondition(PrimaryObject po) {
		BasicDBObject condition = new BasicDBObject();
		if (po instanceof Work) {
			Work work = (Work) po;
			condition.put(
					UserTask.F_PROCESSINSTANCEID,
					work.getValue(Work.F_WF_EXECUTE
							+ IProcessControl.POSTFIX_INSTANCEID));

			condition.put(UserTask.F_STATUS,
					new BasicDBObject().append("$ne", Status.Completed.name()));
			condition.put(UserTask.F_LIFECYCLE_CHANGE_FLAG, Boolean.FALSE);
		}

		return condition;
	}
}
